package com.driving.single.frontend.coach.controller;

import com.driving.single.common.entity.DrivingResult;
import com.driving.single.frontend.coach.service.FrontendCoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/frontend/coach", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class FrontendCoachController {
    @Autowired
    private FrontendCoachService frontendCoachService;

    /**
     * 实现根据主键查询教练接口
     * @param id 主键
     */
    @RequestMapping("/selectCoachById/{id}")
    public DrivingResult selectSchoolById(@PathVariable Long id) {
        try {
            return this.frontendCoachService.selectCoachById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现找教练页面驾校查询 接口
     *
     * @param page        当前页
     * @param rows        页显示数
     * @param area        查询条件：区域(学校名称)
     * @param licenseType 查询条件：驾照类型
     * @param minPrice    查询条件：最小价格
     * @param maxPrice    查询条件：最大价格
     */
    @RequestMapping("selectCoachsWithPage/{page}")
    public DrivingResult selectTbSchoolListByConditionWithPage(@PathVariable Integer page,
                                                               @RequestParam(defaultValue = "4") Integer rows,
                                                               String area,
                                                               String licenseType,
                                                               Integer minPrice,
                                                               Integer maxPrice) {
        try {
            return this.frontendCoachService.selectTbCoachListByConditionWithPage(page, rows, area, licenseType,
                    minPrice,
                    maxPrice);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现根据教练ID   分页查询教练评论   接口
     *
     * @param coach_id 教练主键
     * @param page     当前页
     * @param rows     页显示数
     */
    @RequestMapping("/selectCoachCommentByCoachId/{coach_id}/{page}")
    public DrivingResult selectCoachCommentByCoachIdWithPage(@PathVariable Long coach_id,
                                                          @PathVariable Integer page,
                                                          @RequestParam(defaultValue = "4") Integer rows) {
        try {
            return this.frontendCoachService.selectCoachCommentByCoachIdWithPage(coach_id, page, rows);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }

    /**
     * 实现根据教练ID   查询教练班级及费用   接口
     * @param coach_id 教练主键
     */
    @GetMapping("/selectCoachClassesByCoachId/{coach_id}")
    public DrivingResult selectCoachClassesByCoachId(@PathVariable Long coach_id) {
        try {
            return this.frontendCoachService.selectCoachClassesByCoachId(coach_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DrivingResult.error("error");
    }
}
